package com.atguigu.rabbitmq.three;

import com.atguigu.rabbitmq.util.RabbitMqUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.MessageProperties;

import java.util.Scanner;

/**
 * 消息手动应答时不丢失,放回对应中从新消费
 */
public class Task2 {

    public static final String task_queue_name = "ask_queue";

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMqUtils.getChannel();

        // 申明一个队列
        boolean durable = true; // 需要让queue实现持久化
        channel.queueDeclare(task_queue_name, durable , false ,false,null);

        // 从控制台中输入信息
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            String message = scanner.next();
            // s设置生产者发送消息为持久化消息（要求保存在磁盘上） 保存在内存中
            channel.basicPublish("",task_queue_name, MessageProperties.PERSISTENT_TEXT_PLAIN,message.getBytes("UTF-8"));
            System.out.println("生产者发出消息："+message);
        }
    }

}
